import { headers } from "next/headers"; import { requireUser, jsonError, HttpError } from "@/lib/auth/guard"; import { clientIp } from "@/lib/auth/session"; import { actionSchema, toolAction, getToolRecord } from "@/lib/admin/tools"; export async function POST(req: Request, { params }: { params: Promise<{ id: string }> }) { try { const s = await requireUser(req); const r = await getToolRecord((await params).id); if (!r) throw new HttpError(404, "Not found"); await toolAction(r.id, actionSchema.parse(await req.json()), s, clientIp(await headers())); return Response.json({ ok: true }); } catch (e) { if (e instanceof Error && !(e as any).status && !("issues" in e)) return Response.json({ error: e.message }, { status: 400 }); return jsonError(e); } }